package com.ccnf.web.controller;

import com.ccnf.core.bean.Response;
import com.ccnf.core.bean.ResponseWithData;
import com.ccnf.model.entity.InvitationBrowse;
import com.ccnf.model.entity.InvitationForward;
import com.ccnf.model.entity.InvitationUser;
import com.ccnf.service.InvitationUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(value = "InvitationUserController", description = "邀请函分享记录数据相关API")
@RestController
@RequestMapping("/invitations")
public class InvitationUserController {
    @Autowired
    private InvitationUserService invitationUserService;

    @ApiOperation("录入用户分享邀请函的前置操作，用户用户生成分享的shareId")
    @PostMapping("share")
    public ResponseWithData getShareId(@RequestBody InvitationUser invitationUser) {
        return ResponseWithData.success(invitationUserService.findInvitationUserShareId(invitationUser));
    }

    @ApiOperation("录入邀请函用户转发统计数+1")
    @PostMapping("forward")
    public Response forward(@RequestBody InvitationForward invitationForward) {
        invitationUserService.saveUserForwardInvitation(invitationForward);
        return Response.success();
    }

    @ApiOperation("录入邀请函浏览数据")
    @PostMapping("share/browse")
    public Response share(@RequestBody InvitationBrowse invitationBrowse) {
        invitationUserService.saveInvitationBrowse(invitationBrowse);
        return Response.success();
    }
}